package com.xuelang.pipeline.entry.project;

import com.xuelang.pipeline.app.project.ProjectService;
import com.xuelang.pipeline.app.project.ProjectTypeService;
import com.xuelang.pipeline.client.common.request.PageParam;
import com.xuelang.pipeline.client.common.result.ApiResult;
import com.xuelang.pipeline.client.common.result.PageRecord;
import com.xuelang.pipeline.client.project.IProjectService;
import com.xuelang.pipeline.client.project.dto.ProjectDTO;
import com.xuelang.pipeline.client.project.dto.ProjectQuery;
import com.xuelang.pipeline.client.project.dto.ProjectTypeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 上航-项目管理控制类
 *
 * @author : yixin.lys
 * @date : 2024-09-03 11:53
 **/
@Slf4j
@RestController
@RequestMapping("/projectManagement")
public class ProjectController implements IProjectService {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private ProjectTypeService projectTypeService;

    @Override
    public ApiResult<PageRecord<ProjectDTO>> pageProject(@Valid PageParam<ProjectQuery> pageParam) {
        return ApiResult.success(projectService.pageProjects(pageParam));
    }

    @Override
    public ApiResult<Integer> createProject(@Valid ProjectDTO projectDTO) {
        return ApiResult.success(projectService.createProject(projectDTO));
    }

    @Override
    public ApiResult<Boolean> deleteProjectById(Integer id) {
        return ApiResult.success(projectService.deleteProjectById(id));
    }

    @Override
    public ApiResult<Boolean> updateProject(@Valid ProjectDTO projectDTO) {
        return ApiResult.success(projectService.updateProject(projectDTO));
    }

    @Override
    public ApiResult<ProjectDTO> findProjectById(Integer id) {
        return ApiResult.success(projectService.findProjectById(id));
    }

    @Override
    public ApiResult<List<ProjectDTO>> findAllProjects() {
        return ApiResult.success(projectService.findAllProjects());
    }

    @Override
    public ApiResult<Integer> createProjectType(@Valid ProjectTypeDTO projectTypeDTO) {
        return ApiResult.success(projectTypeService.createProjectType(projectTypeDTO));
    }

    @Override
    public ApiResult<Boolean> deleteProjectTypeById(Integer id) {
        return ApiResult.success(projectTypeService.deleteProjectTypeById(id));
    }

    @Override
    public ApiResult<Boolean> updateProjectType(@Valid ProjectTypeDTO projectTypeDTO) {
        return ApiResult.success(projectTypeService.updateProjectType(projectTypeDTO));
    }

    @Override
    public ApiResult<ProjectTypeDTO> findProjectTypeById(Integer id) {
        return ApiResult.success(projectTypeService.findProjectTypeById(id));
    }

    @Override
    public ApiResult<List<ProjectTypeDTO>> findAllProjectTypes() {
        return ApiResult.success(projectTypeService.findAllProjectTypes());
    }

    @Override
    public ApiResult<Boolean> batchUpdateProjectTypes(@Valid List<ProjectTypeDTO> projectTypeList) {
        return ApiResult.success(projectTypeService.batchUpdateProjectTypes(projectTypeList));
    }
}
